package cn.webrx;

import java.util.Calendar;

public class Str5 {
    public static void main(String[] args) {
        //String类 常用的方法
        String s = "Hello中文";
        //求多个字符
        System.out.println(s.length());
        //求字个字符串有多少个字节
        System.out.println(s.getBytes().length);
        //转换大小写
        System.out.println(s.toUpperCase());
        System.out.println(s.toLowerCase());

        //判断开头
        System.out.println("Hello.java".endsWith("java"));
        //判断结束
        System.out.println("Hello.java".startsWith("H"));
        //判断是不是包括某字符串
        System.out.println(s.contains("ll"));

        //连接字符串
        System.out.println("hello" + "李四，年龄：" + 60 + "岁");
        System.out.println("hello".concat(",Java."));

        //判断字符串内容是否一样
        String s1 = "ok";
        String s2 = "Ok";
        System.out.println(s1==s2);//false
        System.out.println(s1.equals(s2));//false
        System.out.println(s1.equalsIgnoreCase(s2));//false

        //判断位置
        System.out.println("Hello16java".indexOf("16"));//5
        System.out.println("Hello16java".indexOf("66"));//-1
        System.out.println("H16ello16ja16va".indexOf("16"));//1
        System.out.println("H16ello16ja16va".indexOf("16",8));//11
        System.out.println("H16ello16ja16va".lastIndexOf("16"));//11

        //charAt();
        Calendar c = Calendar.getInstance();
        int k = c.get(Calendar.DAY_OF_WEEK)-1;
        System.out.println("星期" + "日一二三四五六".charAt(k));

        //截取字符串
        System.out.println("hellojava".substring(3));//lojava
        System.out.println("hellojava".substring(3,6));//loj

        //替换字符串
        System.out.println("hello,abc-abc-abc".replace("abc","java").replace("java",""));
    }
}
